package cn.ibizlab.odoo.core.odoo_sale.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Isale_order;
import cn.ibizlab.odoo.core.odoo_sale.domain.Sale_order;
import cn.ibizlab.odoo.core.odoo_sale.filter.Sale_orderSearchContext;
import cn.ibizlab.odoo.core.odoo_sale.service.ISale_orderService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[销售订单] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Sale_orderServiceImpl implements ISale_orderService {

    @Autowired
    private cn.ibizlab.odoo.core.odoo_sale.service.ISale_order_lineService sale_order_lineService;

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Isale_orderClientService sale_orderClientService;

    @Override
    public void updateBatch(List<Sale_order> sale_orders, int batchSize) {

        //sale_orderClientService.updateBatch(sale_orders,batchSize) ;

    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //sale_orderClientService.removeBatch(sale_orders) ;

    }

    @Override
    public boolean update(Sale_order sale_order) {
        boolean bOk = false ;
        Isale_order clientModel = this.convert2Model(sale_order,null);
        sale_orderClientService.update(clientModel) ;
        this.convert2Domain(clientModel,sale_order) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public Sale_order get(Integer id) {
        Isale_order clientModel = sale_orderClientService.createModel();
        clientModel.setId(id);
        sale_orderClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Sale_order get(Sale_order sale_order) {
        Sale_order retsale_order = this.get(sale_order.getId()) ;
    	BeanCopier copier=BeanCopier.create(retsale_order.getClass(), sale_order.getClass(), false);
        copier.copy(retsale_order, sale_order, null);
        return sale_order ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Isale_order clientModel = sale_orderClientService.createModel();
        clientModel.setId(id);
        sale_orderClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void createBatch(List<Sale_order> sale_orders, int batchSize) {

                        //sale_orderClientService.createBatch(sale_orders,batchSize) ;

    }

    @Override
    public boolean create(Sale_order sale_order) {
        boolean bOk = false ;
        Isale_order clientModel = this.convert2Model(sale_order,null);
        sale_orderClientService.create(clientModel) ;
        this.convert2Domain(clientModel,sale_order);
        bOk = true ;

        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Sale_order> searchDefault(Sale_orderSearchContext context) {
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据分析账户查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_analytic_account(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据税科目调整查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_fiscal_position(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据贸易条款查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_incoterm(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据付款条款查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_payment_term(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据线索/商机查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_opportunity(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据销售渠道查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_team(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据价格表查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_pricelist(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据公司查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_company(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_partner(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_partner_invoice(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据联系人查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_partner_shipping(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_create(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_user(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_write(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据报价单模板查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_sale_order_template(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据仓库查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_warehouse(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据UTM 营销活动查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_campaign(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据UTM媒体查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_medium(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据UTM来源查询
     */
    @Override
    public Page<Sale_order> selectByOdoo_source(Integer id){
        Sale_orderSearchContext context = new Sale_orderSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Sale_order> list = new ArrayList<Sale_order>();
        Page<cn.ibizlab.odoo.core.client.model.Isale_order> clientModelList = sale_orderClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isale_order clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Sale_order>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Isale_order convert2Model(Sale_order domain , Isale_order model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = sale_orderClientService.createModel() ;
        }

         if(domain.getDate_orderDirtyFlag())
            model.setDate_order(domain.getDate_order());
         if(domain.getInvoice_idsDirtyFlag())
            model.setInvoice_ids(domain.getInvoice_ids());
         if(domain.getActivity_type_idDirtyFlag())
            model.setActivity_type_id(domain.getActivity_type_id());
         if(domain.getAmount_untaxedDirtyFlag())
            model.setAmount_untaxed(domain.getAmount_untaxed());
         if(domain.getValidity_dateDirtyFlag())
            model.setValidity_date(domain.getValidity_date());
         if(domain.getAmount_undiscountedDirtyFlag())
            model.setAmount_undiscounted(domain.getAmount_undiscounted());
         if(domain.getInvoice_countDirtyFlag())
            model.setInvoice_count(domain.getInvoice_count());
         if(domain.getAccess_warningDirtyFlag())
            model.setAccess_warning(domain.getAccess_warning());
         if(domain.getWarning_stockDirtyFlag())
            model.setWarning_stock(domain.getWarning_stock());
         if(domain.getMessage_is_followerDirtyFlag())
            model.setMessage_is_follower(domain.getMessage_is_follower());
         if(domain.getEffective_dateDirtyFlag())
            model.setEffective_date(domain.getEffective_date());
         if(domain.getWebsite_idDirtyFlag())
            model.setWebsite_id(domain.getWebsite_id());
         if(domain.getRequire_signatureDirtyFlag())
            model.setRequire_signature(domain.getRequire_signature());
         if(domain.getCurrency_rateDirtyFlag())
            model.setCurrency_rate(domain.getCurrency_rate());
         if(domain.getPicking_policyDirtyFlag())
            model.setPicking_policy(domain.getPicking_policy());
         if(domain.getActivity_date_deadlineDirtyFlag())
            model.setActivity_date_deadline(domain.getActivity_date_deadline());
         if(domain.getSignatureDirtyFlag())
            model.setSignature(domain.getSignature());
         if(domain.getProcurement_group_idDirtyFlag())
            model.setProcurement_group_id(domain.getProcurement_group_id());
         if(domain.getActivity_stateDirtyFlag())
            model.setActivity_state(domain.getActivity_state());
         if(domain.getCart_quantityDirtyFlag())
            model.setCart_quantity(domain.getCart_quantity());
         if(domain.getType_nameDirtyFlag())
            model.setType_name(domain.getType_name());
         if(domain.getMessage_main_attachment_idDirtyFlag())
            model.setMessage_main_attachment_id(domain.getMessage_main_attachment_id());
         if(domain.getActivity_summaryDirtyFlag())
            model.setActivity_summary(domain.getActivity_summary());
         if(domain.getDelivery_countDirtyFlag())
            model.setDelivery_count(domain.getDelivery_count());
         if(domain.getSigned_byDirtyFlag())
            model.setSigned_by(domain.getSigned_by());
         if(domain.getOrder_lineDirtyFlag())
            model.setOrder_line(domain.getOrder_line());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getRequire_paymentDirtyFlag())
            model.setRequire_payment(domain.getRequire_payment());
         if(domain.getOnly_servicesDirtyFlag())
            model.setOnly_services(domain.getOnly_services());
         if(domain.getMessage_partner_idsDirtyFlag())
            model.setMessage_partner_ids(domain.getMessage_partner_ids());
         if(domain.getWebsite_order_lineDirtyFlag())
            model.setWebsite_order_line(domain.getWebsite_order_line());
         if(domain.getReferenceDirtyFlag())
            model.setReference(domain.getReference());
         if(domain.getMessage_attachment_countDirtyFlag())
            model.setMessage_attachment_count(domain.getMessage_attachment_count());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getInvoice_statusDirtyFlag())
            model.setInvoice_status(domain.getInvoice_status());
         if(domain.getTag_idsDirtyFlag())
            model.setTag_ids(domain.getTag_ids());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getTransaction_idsDirtyFlag())
            model.setTransaction_ids(domain.getTransaction_ids());
         if(domain.getMessage_needaction_counterDirtyFlag())
            model.setMessage_needaction_counter(domain.getMessage_needaction_counter());
         if(domain.getIs_abandoned_cartDirtyFlag())
            model.setIs_abandoned_cart(domain.getIs_abandoned_cart());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getMessage_has_errorDirtyFlag())
            model.setMessage_has_error(domain.getMessage_has_error());
         if(domain.getExpense_countDirtyFlag())
            model.setExpense_count(domain.getExpense_count());
         if(domain.getAuthorized_transaction_idsDirtyFlag())
            model.setAuthorized_transaction_ids(domain.getAuthorized_transaction_ids());
         if(domain.getCommitment_dateDirtyFlag())
            model.setCommitment_date(domain.getCommitment_date());
         if(domain.getIs_expiredDirtyFlag())
            model.setIs_expired(domain.getIs_expired());
         if(domain.getWebsite_message_idsDirtyFlag())
            model.setWebsite_message_ids(domain.getWebsite_message_ids());
         if(domain.getRemaining_validity_daysDirtyFlag())
            model.setRemaining_validity_days(domain.getRemaining_validity_days());
         if(domain.getExpected_dateDirtyFlag())
            model.setExpected_date(domain.getExpected_date());
         if(domain.getPurchase_order_countDirtyFlag())
            model.setPurchase_order_count(domain.getPurchase_order_count());
         if(domain.getMessage_follower_idsDirtyFlag())
            model.setMessage_follower_ids(domain.getMessage_follower_ids());
         if(domain.getAccess_urlDirtyFlag())
            model.setAccess_url(domain.getAccess_url());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getMessage_channel_idsDirtyFlag())
            model.setMessage_channel_ids(domain.getMessage_channel_ids());
         if(domain.getSale_order_option_idsDirtyFlag())
            model.setSale_order_option_ids(domain.getSale_order_option_ids());
         if(domain.getMessage_idsDirtyFlag())
            model.setMessage_ids(domain.getMessage_ids());
         if(domain.getOriginDirtyFlag())
            model.setOrigin(domain.getOrigin());
         if(domain.getConfirmation_dateDirtyFlag())
            model.setConfirmation_date(domain.getConfirmation_date());
         if(domain.getNoteDirtyFlag())
            model.setNote(domain.getNote());
         if(domain.getAmount_by_groupDirtyFlag())
            model.setAmount_by_group(domain.getAmount_by_group());
         if(domain.getPicking_idsDirtyFlag())
            model.setPicking_ids(domain.getPicking_ids());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getActivity_idsDirtyFlag())
            model.setActivity_ids(domain.getActivity_ids());
         if(domain.getMessage_has_error_counterDirtyFlag())
            model.setMessage_has_error_counter(domain.getMessage_has_error_counter());
         if(domain.getAccess_tokenDirtyFlag())
            model.setAccess_token(domain.getAccess_token());
         if(domain.getAmount_totalDirtyFlag())
            model.setAmount_total(domain.getAmount_total());
         if(domain.getClient_order_refDirtyFlag())
            model.setClient_order_ref(domain.getClient_order_ref());
         if(domain.getMessage_unreadDirtyFlag())
            model.setMessage_unread(domain.getMessage_unread());
         if(domain.getActivity_user_idDirtyFlag())
            model.setActivity_user_id(domain.getActivity_user_id());
         if(domain.getMessage_unread_counterDirtyFlag())
            model.setMessage_unread_counter(domain.getMessage_unread_counter());
         if(domain.getCart_recovery_email_sentDirtyFlag())
            model.setCart_recovery_email_sent(domain.getCart_recovery_email_sent());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getMessage_needactionDirtyFlag())
            model.setMessage_needaction(domain.getMessage_needaction());
         if(domain.getAmount_taxDirtyFlag())
            model.setAmount_tax(domain.getAmount_tax());
         if(domain.getExpense_idsDirtyFlag())
            model.setExpense_ids(domain.getExpense_ids());
         if(domain.getPartner_invoice_id_textDirtyFlag())
            model.setPartner_invoice_id_text(domain.getPartner_invoice_id_text());
         if(domain.getIncoterm_textDirtyFlag())
            model.setIncoterm_text(domain.getIncoterm_text());
         if(domain.getTeam_id_textDirtyFlag())
            model.setTeam_id_text(domain.getTeam_id_text());
         if(domain.getAnalytic_account_id_textDirtyFlag())
            model.setAnalytic_account_id_text(domain.getAnalytic_account_id_text());
         if(domain.getPartner_id_textDirtyFlag())
            model.setPartner_id_text(domain.getPartner_id_text());
         if(domain.getCampaign_id_textDirtyFlag())
            model.setCampaign_id_text(domain.getCampaign_id_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getCompany_id_textDirtyFlag())
            model.setCompany_id_text(domain.getCompany_id_text());
         if(domain.getPartner_shipping_id_textDirtyFlag())
            model.setPartner_shipping_id_text(domain.getPartner_shipping_id_text());
         if(domain.getWarehouse_id_textDirtyFlag())
            model.setWarehouse_id_text(domain.getWarehouse_id_text());
         if(domain.getUser_id_textDirtyFlag())
            model.setUser_id_text(domain.getUser_id_text());
         if(domain.getOpportunity_id_textDirtyFlag())
            model.setOpportunity_id_text(domain.getOpportunity_id_text());
         if(domain.getSource_id_textDirtyFlag())
            model.setSource_id_text(domain.getSource_id_text());
         if(domain.getMedium_id_textDirtyFlag())
            model.setMedium_id_text(domain.getMedium_id_text());
         if(domain.getFiscal_position_id_textDirtyFlag())
            model.setFiscal_position_id_text(domain.getFiscal_position_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getPricelist_id_textDirtyFlag())
            model.setPricelist_id_text(domain.getPricelist_id_text());
         if(domain.getPayment_term_id_textDirtyFlag())
            model.setPayment_term_id_text(domain.getPayment_term_id_text());
         if(domain.getSale_order_template_id_textDirtyFlag())
            model.setSale_order_template_id_text(domain.getSale_order_template_id_text());
         if(domain.getCurrency_idDirtyFlag())
            model.setCurrency_id(domain.getCurrency_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getTeam_idDirtyFlag())
            model.setTeam_id(domain.getTeam_id());
         if(domain.getPartner_invoice_idDirtyFlag())
            model.setPartner_invoice_id(domain.getPartner_invoice_id());
         if(domain.getFiscal_position_idDirtyFlag())
            model.setFiscal_position_id(domain.getFiscal_position_id());
         if(domain.getPartner_idDirtyFlag())
            model.setPartner_id(domain.getPartner_id());
         if(domain.getCampaign_idDirtyFlag())
            model.setCampaign_id(domain.getCampaign_id());
         if(domain.getSource_idDirtyFlag())
            model.setSource_id(domain.getSource_id());
         if(domain.getSale_order_template_idDirtyFlag())
            model.setSale_order_template_id(domain.getSale_order_template_id());
         if(domain.getUser_idDirtyFlag())
            model.setUser_id(domain.getUser_id());
         if(domain.getCompany_idDirtyFlag())
            model.setCompany_id(domain.getCompany_id());
         if(domain.getMedium_idDirtyFlag())
            model.setMedium_id(domain.getMedium_id());
         if(domain.getAnalytic_account_idDirtyFlag())
            model.setAnalytic_account_id(domain.getAnalytic_account_id());
         if(domain.getPayment_term_idDirtyFlag())
            model.setPayment_term_id(domain.getPayment_term_id());
         if(domain.getPartner_shipping_idDirtyFlag())
            model.setPartner_shipping_id(domain.getPartner_shipping_id());
         if(domain.getOpportunity_idDirtyFlag())
            model.setOpportunity_id(domain.getOpportunity_id());
         if(domain.getIncotermDirtyFlag())
            model.setIncoterm(domain.getIncoterm());
         if(domain.getPricelist_idDirtyFlag())
            model.setPricelist_id(domain.getPricelist_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getWarehouse_idDirtyFlag())
            model.setWarehouse_id(domain.getWarehouse_id());
         //嵌套数据
         List<cn.ibizlab.odoo.core.client.model.Isale_order_line> sale_order_lines = new ArrayList<cn.ibizlab.odoo.core.client.model.Isale_order_line>();
         for(cn.ibizlab.odoo.core.odoo_sale.domain.Sale_order_line sale_order_line : domain.getSale_order_lines()){
             sale_order_lines.add(sale_order_lineService.convert2Model(sale_order_line,null));
         }
         model.setSale_order_lines(sale_order_lines);
        return model ;
    }

    public Sale_order convert2Domain( Isale_order model ,Sale_order domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Sale_order();
        }

        if(model.getDate_orderDirtyFlag())
            domain.setDate_order(model.getDate_order());
        if(model.getInvoice_idsDirtyFlag())
            domain.setInvoice_ids(model.getInvoice_ids());
        if(model.getActivity_type_idDirtyFlag())
            domain.setActivity_type_id(model.getActivity_type_id());
        if(model.getAmount_untaxedDirtyFlag())
            domain.setAmount_untaxed(model.getAmount_untaxed());
        if(model.getValidity_dateDirtyFlag())
            domain.setValidity_date(model.getValidity_date());
        if(model.getAmount_undiscountedDirtyFlag())
            domain.setAmount_undiscounted(model.getAmount_undiscounted());
        if(model.getInvoice_countDirtyFlag())
            domain.setInvoice_count(model.getInvoice_count());
        if(model.getAccess_warningDirtyFlag())
            domain.setAccess_warning(model.getAccess_warning());
        if(model.getWarning_stockDirtyFlag())
            domain.setWarning_stock(model.getWarning_stock());
        if(model.getMessage_is_followerDirtyFlag())
            domain.setMessage_is_follower(model.getMessage_is_follower());
        if(model.getEffective_dateDirtyFlag())
            domain.setEffective_date(model.getEffective_date());
        if(model.getWebsite_idDirtyFlag())
            domain.setWebsite_id(model.getWebsite_id());
        if(model.getRequire_signatureDirtyFlag())
            domain.setRequire_signature(model.getRequire_signature());
        if(model.getCurrency_rateDirtyFlag())
            domain.setCurrency_rate(model.getCurrency_rate());
        if(model.getPicking_policyDirtyFlag())
            domain.setPicking_policy(model.getPicking_policy());
        if(model.getActivity_date_deadlineDirtyFlag())
            domain.setActivity_date_deadline(model.getActivity_date_deadline());
        if(model.getSignatureDirtyFlag())
            domain.setSignature(model.getSignature());
        if(model.getProcurement_group_idDirtyFlag())
            domain.setProcurement_group_id(model.getProcurement_group_id());
        if(model.getActivity_stateDirtyFlag())
            domain.setActivity_state(model.getActivity_state());
        if(model.getCart_quantityDirtyFlag())
            domain.setCart_quantity(model.getCart_quantity());
        if(model.getType_nameDirtyFlag())
            domain.setType_name(model.getType_name());
        if(model.getMessage_main_attachment_idDirtyFlag())
            domain.setMessage_main_attachment_id(model.getMessage_main_attachment_id());
        if(model.getActivity_summaryDirtyFlag())
            domain.setActivity_summary(model.getActivity_summary());
        if(model.getDelivery_countDirtyFlag())
            domain.setDelivery_count(model.getDelivery_count());
        if(model.getSigned_byDirtyFlag())
            domain.setSigned_by(model.getSigned_by());
        if(model.getOrder_lineDirtyFlag())
            domain.setOrder_line(model.getOrder_line());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getRequire_paymentDirtyFlag())
            domain.setRequire_payment(model.getRequire_payment());
        if(model.getOnly_servicesDirtyFlag())
            domain.setOnly_services(model.getOnly_services());
        if(model.getMessage_partner_idsDirtyFlag())
            domain.setMessage_partner_ids(model.getMessage_partner_ids());
        if(model.getWebsite_order_lineDirtyFlag())
            domain.setWebsite_order_line(model.getWebsite_order_line());
        if(model.getReferenceDirtyFlag())
            domain.setReference(model.getReference());
        if(model.getMessage_attachment_countDirtyFlag())
            domain.setMessage_attachment_count(model.getMessage_attachment_count());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getInvoice_statusDirtyFlag())
            domain.setInvoice_status(model.getInvoice_status());
        if(model.getTag_idsDirtyFlag())
            domain.setTag_ids(model.getTag_ids());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getTransaction_idsDirtyFlag())
            domain.setTransaction_ids(model.getTransaction_ids());
        if(model.getMessage_needaction_counterDirtyFlag())
            domain.setMessage_needaction_counter(model.getMessage_needaction_counter());
        if(model.getIs_abandoned_cartDirtyFlag())
            domain.setIs_abandoned_cart(model.getIs_abandoned_cart());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getMessage_has_errorDirtyFlag())
            domain.setMessage_has_error(model.getMessage_has_error());
        if(model.getExpense_countDirtyFlag())
            domain.setExpense_count(model.getExpense_count());
        if(model.getAuthorized_transaction_idsDirtyFlag())
            domain.setAuthorized_transaction_ids(model.getAuthorized_transaction_ids());
        if(model.getCommitment_dateDirtyFlag())
            domain.setCommitment_date(model.getCommitment_date());
        if(model.getIs_expiredDirtyFlag())
            domain.setIs_expired(model.getIs_expired());
        if(model.getWebsite_message_idsDirtyFlag())
            domain.setWebsite_message_ids(model.getWebsite_message_ids());
        if(model.getRemaining_validity_daysDirtyFlag())
            domain.setRemaining_validity_days(model.getRemaining_validity_days());
        if(model.getExpected_dateDirtyFlag())
            domain.setExpected_date(model.getExpected_date());
        if(model.getPurchase_order_countDirtyFlag())
            domain.setPurchase_order_count(model.getPurchase_order_count());
        if(model.getMessage_follower_idsDirtyFlag())
            domain.setMessage_follower_ids(model.getMessage_follower_ids());
        if(model.getAccess_urlDirtyFlag())
            domain.setAccess_url(model.getAccess_url());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getMessage_channel_idsDirtyFlag())
            domain.setMessage_channel_ids(model.getMessage_channel_ids());
        if(model.getSale_order_option_idsDirtyFlag())
            domain.setSale_order_option_ids(model.getSale_order_option_ids());
        if(model.getMessage_idsDirtyFlag())
            domain.setMessage_ids(model.getMessage_ids());
        if(model.getOriginDirtyFlag())
            domain.setOrigin(model.getOrigin());
        if(model.getConfirmation_dateDirtyFlag())
            domain.setConfirmation_date(model.getConfirmation_date());
        if(model.getNoteDirtyFlag())
            domain.setNote(model.getNote());
        if(model.getAmount_by_groupDirtyFlag())
            domain.setAmount_by_group(model.getAmount_by_group());
        if(model.getPicking_idsDirtyFlag())
            domain.setPicking_ids(model.getPicking_ids());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getActivity_idsDirtyFlag())
            domain.setActivity_ids(model.getActivity_ids());
        if(model.getMessage_has_error_counterDirtyFlag())
            domain.setMessage_has_error_counter(model.getMessage_has_error_counter());
        if(model.getAccess_tokenDirtyFlag())
            domain.setAccess_token(model.getAccess_token());
        if(model.getAmount_totalDirtyFlag())
            domain.setAmount_total(model.getAmount_total());
        if(model.getClient_order_refDirtyFlag())
            domain.setClient_order_ref(model.getClient_order_ref());
        if(model.getMessage_unreadDirtyFlag())
            domain.setMessage_unread(model.getMessage_unread());
        if(model.getActivity_user_idDirtyFlag())
            domain.setActivity_user_id(model.getActivity_user_id());
        if(model.getMessage_unread_counterDirtyFlag())
            domain.setMessage_unread_counter(model.getMessage_unread_counter());
        if(model.getCart_recovery_email_sentDirtyFlag())
            domain.setCart_recovery_email_sent(model.getCart_recovery_email_sent());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getMessage_needactionDirtyFlag())
            domain.setMessage_needaction(model.getMessage_needaction());
        if(model.getAmount_taxDirtyFlag())
            domain.setAmount_tax(model.getAmount_tax());
        if(model.getExpense_idsDirtyFlag())
            domain.setExpense_ids(model.getExpense_ids());
        if(model.getPartner_invoice_id_textDirtyFlag())
            domain.setPartner_invoice_id_text(model.getPartner_invoice_id_text());
        if(model.getIncoterm_textDirtyFlag())
            domain.setIncoterm_text(model.getIncoterm_text());
        if(model.getTeam_id_textDirtyFlag())
            domain.setTeam_id_text(model.getTeam_id_text());
        if(model.getAnalytic_account_id_textDirtyFlag())
            domain.setAnalytic_account_id_text(model.getAnalytic_account_id_text());
        if(model.getPartner_id_textDirtyFlag())
            domain.setPartner_id_text(model.getPartner_id_text());
        if(model.getCampaign_id_textDirtyFlag())
            domain.setCampaign_id_text(model.getCampaign_id_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getCompany_id_textDirtyFlag())
            domain.setCompany_id_text(model.getCompany_id_text());
        if(model.getPartner_shipping_id_textDirtyFlag())
            domain.setPartner_shipping_id_text(model.getPartner_shipping_id_text());
        if(model.getWarehouse_id_textDirtyFlag())
            domain.setWarehouse_id_text(model.getWarehouse_id_text());
        if(model.getUser_id_textDirtyFlag())
            domain.setUser_id_text(model.getUser_id_text());
        if(model.getOpportunity_id_textDirtyFlag())
            domain.setOpportunity_id_text(model.getOpportunity_id_text());
        if(model.getSource_id_textDirtyFlag())
            domain.setSource_id_text(model.getSource_id_text());
        if(model.getMedium_id_textDirtyFlag())
            domain.setMedium_id_text(model.getMedium_id_text());
        if(model.getFiscal_position_id_textDirtyFlag())
            domain.setFiscal_position_id_text(model.getFiscal_position_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getPricelist_id_textDirtyFlag())
            domain.setPricelist_id_text(model.getPricelist_id_text());
        if(model.getPayment_term_id_textDirtyFlag())
            domain.setPayment_term_id_text(model.getPayment_term_id_text());
        if(model.getSale_order_template_id_textDirtyFlag())
            domain.setSale_order_template_id_text(model.getSale_order_template_id_text());
        if(model.getCurrency_idDirtyFlag())
            domain.setCurrency_id(model.getCurrency_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getTeam_idDirtyFlag())
            domain.setTeam_id(model.getTeam_id());
        if(model.getPartner_invoice_idDirtyFlag())
            domain.setPartner_invoice_id(model.getPartner_invoice_id());
        if(model.getFiscal_position_idDirtyFlag())
            domain.setFiscal_position_id(model.getFiscal_position_id());
        if(model.getPartner_idDirtyFlag())
            domain.setPartner_id(model.getPartner_id());
        if(model.getCampaign_idDirtyFlag())
            domain.setCampaign_id(model.getCampaign_id());
        if(model.getSource_idDirtyFlag())
            domain.setSource_id(model.getSource_id());
        if(model.getSale_order_template_idDirtyFlag())
            domain.setSale_order_template_id(model.getSale_order_template_id());
        if(model.getUser_idDirtyFlag())
            domain.setUser_id(model.getUser_id());
        if(model.getCompany_idDirtyFlag())
            domain.setCompany_id(model.getCompany_id());
        if(model.getMedium_idDirtyFlag())
            domain.setMedium_id(model.getMedium_id());
        if(model.getAnalytic_account_idDirtyFlag())
            domain.setAnalytic_account_id(model.getAnalytic_account_id());
        if(model.getPayment_term_idDirtyFlag())
            domain.setPayment_term_id(model.getPayment_term_id());
        if(model.getPartner_shipping_idDirtyFlag())
            domain.setPartner_shipping_id(model.getPartner_shipping_id());
        if(model.getOpportunity_idDirtyFlag())
            domain.setOpportunity_id(model.getOpportunity_id());
        if(model.getIncotermDirtyFlag())
            domain.setIncoterm(model.getIncoterm());
        if(model.getPricelist_idDirtyFlag())
            domain.setPricelist_id(model.getPricelist_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getWarehouse_idDirtyFlag())
            domain.setWarehouse_id(model.getWarehouse_id());
         //嵌套数据
         List<cn.ibizlab.odoo.core.odoo_sale.domain.Sale_order_line> sale_order_lines = new ArrayList<cn.ibizlab.odoo.core.odoo_sale.domain.Sale_order_line>();
         for(cn.ibizlab.odoo.core.client.model.Isale_order_line sale_order_line : model.getSale_order_lines()){
             sale_order_lines.add(sale_order_lineService.convert2Domain(sale_order_line,null));
         }
         domain.setSale_order_lines(sale_order_lines);
        return domain ;
    }

    //更新嵌套[销售订单行]
    private void _updateSale_order_lines(Sale_order sale_order){
        Map<Integer,cn.ibizlab.odoo.core.odoo_sale.domain.Sale_order_line> oldMapSale_order_lines = new HashMap<Integer,cn.ibizlab.odoo.core.odoo_sale.domain.Sale_order_line>() ;
        Page<cn.ibizlab.odoo.core.odoo_sale.domain.Sale_order_line> oldSale_order_lines = sale_order_lineService.selectByOdoo_order(sale_order.getId());
        for(cn.ibizlab.odoo.core.odoo_sale.domain.Sale_order_line sale_order_line : oldSale_order_lines){
            oldMapSale_order_lines.put(sale_order_line.getId(),sale_order_line);
        }

        Map<Integer,cn.ibizlab.odoo.core.odoo_sale.domain.Sale_order_line> newMapSale_order_lines = new HashMap<Integer,cn.ibizlab.odoo.core.odoo_sale.domain.Sale_order_line>() ;
        List<cn.ibizlab.odoo.core.odoo_sale.domain.Sale_order_line> newSale_order_lines = sale_order.getSale_order_lines() ;
        for(cn.ibizlab.odoo.core.odoo_sale.domain.Sale_order_line sale_order_line : newSale_order_lines){
            sale_order_line.setOrder_id(sale_order.getId());
            if(sale_order_line.getId() == null ){
                sale_order_lineService.create(sale_order_line) ;
                continue ;
            }
            newMapSale_order_lines.put(sale_order_line.getId(),sale_order_line) ;
            if(oldMapSale_order_lines.containsKey(sale_order_line.getId())) {
                sale_order_lineService.update(sale_order_line);
            }else {
                sale_order_lineService.create(sale_order_line);
            }
        }

        //删除多余数据
        for(Integer key : oldMapSale_order_lines.keySet()){
            if(!newMapSale_order_lines.containsKey(key))
                sale_order_lineService.remove(key) ;
        }
    }


}
